<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>可变长参数</title>
</head>
<body>
<p>不定参数用来表示不确定参数个数，形如，...变量名，由...加上一个具名参数标识符组成。
    </p>
<p> 具名参数只能放在参数组的最后，并且有且只有一个不定参数。</p>
<script>
   function sum(...args) {
       let result = 0;

       args.forEach(function (val) {
           result+=val;
       });
       return result;
   }
   console.log(sum(1,2,3));//6
   console.log(sum(1,2,3,4,5,6,7,8,9,10));//55


   function sum1(...args) {
       let result = 0;

       //箭头函数
       args.forEach(val => {
           result += val;
       });

       return result;
   }

   console.log(sum1(1,2,3));//6
   console.log(sum1(1,2,3,4,5,6,7,8,9,10));//55
</script>
</body>
</html>
